Raise the VM_BAD_POWER_STATE error with VM.send_sysrq if the domain is not
authorEwan Mellor <ewan@xensource.com>
Thu, 15 Mar 2007 22:15:12 +0000 (22:15 +0000)
committerEwan Mellor <ewan@xensource.com>
Thu, 15 Mar 2007 22:15:12 +0000 (22:15 +0000)
running.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/XendAPI.py

index 10024070a934040c2e1acd16b31339aa914f0ec2..cb444f04d1e27eb3859fec920bcc4af98d547fc8 100644 (file)
@@ -1515,11 +1515,16 @@ class XendAPI(object):
                                      "domain_unpause", vm_ref)
 
     def VM_send_sysrq(self, _, vm_ref, req):
-        xendom = XendDomain.instance()
-        xeninfo = xendom.get_vm_by_uuid(vm_ref)
+        xeninfo = XendDomain.instance().get_vm_by_uuid(vm_ref)
+        if xeninfo.state != XEN_API_VM_POWER_STATE_RUNNING:
+            return xen_api_error(
+                ['VM_BAD_POWER_STATE', vm_ref,
+                 XendDomain.POWER_STATE_NAMES[XEN_API_VM_POWER_STATE_RUNNING],
+                 XendDomain.POWER_STATE_NAMES[xeninfo.state]])
         xeninfo.send_sysrq(req)
         return xen_api_success_void()
 
+
     # Xen API: Class VM_metrics
     # ----------------------------------------------------------------